home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / bitmap / fopen.frm < prev    next >
Text File  |  1995-05-08  |  14KB  |  488 lines

  1. VERSION 2.00
  2. Begin Form FOpenForm 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "File Open"
  5.    ClientHeight    =   3150
  6.    ClientLeft      =   3000
  7.    ClientTop       =   2460
  8.    ClientWidth     =   4980
  9.    Height          =   3555
  10.    Icon            =   FOPEN.FRX:0000
  11.    Left            =   2940
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   3150
  17.    ScaleWidth      =   4980
  18.    Top             =   2115
  19.    Width           =   5100
  20.    Begin ListBox List1 
  21.       Height          =   1785
  22.       Left            =   1965
  23.       Sorted          =   -1  'True
  24.       TabIndex        =   1
  25.       Top             =   1170
  26.       Width           =   1575
  27.    End
  28.    Begin FileListBox File1 
  29.       Height          =   1785
  30.       Left            =   165
  31.       TabIndex        =   3
  32.       Top             =   1170
  33.       Width           =   1575
  34.    End
  35.    Begin CommandButton Command3 
  36.       Caption         =   "Load &Null"
  37.       Height          =   375
  38.       Left            =   3705
  39.       TabIndex        =   10
  40.       Top             =   1095
  41.       Width           =   1095
  42.    End
  43.    Begin CommandButton Command2 
  44.       Caption         =   "&Cancel"
  45.       Height          =   375
  46.       Left            =   3705
  47.       TabIndex        =   7
  48.       Top             =   615
  49.       Width           =   1095
  50.    End
  51.    Begin CommandButton Command1 
  52.       Caption         =   "&Open"
  53.       Default         =   -1  'True
  54.       Height          =   375
  55.       Left            =   3705
  56.       TabIndex        =   6
  57.       Top             =   135
  58.       Width           =   1095
  59.    End
  60.    Begin TextBox Text1 
  61.       Height          =   315
  62.       Left            =   1140
  63.       TabIndex        =   5
  64.       Text            =   "FileName"
  65.       Top             =   165
  66.       Width           =   2400
  67.    End
  68.    Begin Label DirLabel 
  69.       Caption         =   "&Directories:"
  70.       Height          =   195
  71.       Left            =   1970
  72.       TabIndex        =   0
  73.       Top             =   900
  74.       Width           =   1035
  75.    End
  76.    Begin Label FilesLabel 
  77.       AutoSize        =   -1  'True
  78.       Caption         =   "&Files:"
  79.       Height          =   195
  80.       Left            =   170
  81.       TabIndex        =   2
  82.       Top             =   915
  83.       Width           =   465
  84.    End
  85.    Begin Label Label1 
  86.       Caption         =   "Label1"
  87.       Height          =   255
  88.       Left            =   1155
  89.       TabIndex        =   9
  90.       Top             =   580
  91.       Width           =   2310
  92.    End
  93.    Begin Label Label4 
  94.       Caption         =   "Directory:"
  95.       Height          =   255
  96.       Left            =   170
  97.       TabIndex        =   8
  98.       Top             =   580
  99.       Width           =   855
  100.    End
  101.    Begin Label FNameLabel 
  102.       Caption         =   "File &Name:"
  103.       Height          =   255
  104.       Left            =   170
  105.       TabIndex        =   4
  106.       Top             =   210
  107.       Width           =   975
  108.    End
  109. End
  110. 'You are welcome to use FOPEN in your programs free of charge.
  111. 'If you make any improvements send me a copy at CIS-MAL 73667,1755
  112. 'Costas Kitsos
  113. DefInt A-Z
  114. Dim TheFocus%                   ' Handle for Drive/Subdirectory ListBox
  115. Dim List1Flag%                  ' Flag for Drive/Subdirectory ListBox 0 or 1
  116. Dim Text1Flag%                  ' Flag for EM_LIMITTEXT
  117. Dim TheDrive$                   ' The selected drive
  118. Dim LastChange As Integer       ' Flag used when processing selections
  119.  
  120. Function BuildSpec (fpath As String) As String
  121.  ' builds the spec for SendMessage
  122.     If Right$(fpath, 1) <> "\" Then
  123.     s$ = fpath + "\*.*"
  124.     Else
  125.     s$ = fpath + "*.*"
  126.     End If
  127.     BuildSpec = s$
  128.     s$ = ""
  129. End Function
  130.  
  131. Sub ChangeDir (b$)
  132. ' change to the new directory and update List1
  133.  List1.SetFocus
  134.  TheFocus% = GetFocus()
  135.  If InStr(b$, ":") Then b$ = Right$(b$, Len(b$) - 2)
  136.  If Left$(b$, 1) <> "\" Then b$ = "\" + b$
  137.  On Error Resume Next
  138.    File1.Path = TheDrive$ + b$
  139.    Label1.caption = File1.Path
  140.    y& = SendMessage(TheFocus%, LB_RESETCONTENT, 0, ByVal "")
  141.    x& = SendMessage(TheFocus%, LB_DIR, &HC010, ByVal BuildSpec((File1.Path)))
  142.  If Err Then
  143.  ' you may add a MsgBox error message here if you think it's
  144.  ' necessary.
  145.  End If
  146. End Sub
  147.  
  148. Sub ChangeDrive (a$, ErrState%)
  149.     OldPath$ = File1.Path
  150.     List1.SetFocus
  151.     TheFocus% = GetFocus()
  152.  ' try to change to the new drive
  153.     On Error Resume Next
  154.         File1.Path = a$ + ":"
  155.         y& = SendMessage(TheFocus%, LB_RESETCONTENT, 0, ByVal "")
  156.         s$ = a$ + ":*.*"
  157.         x& = SendMessage(TheFocus%, LB_DIR, &HC010, ByVal s$)
  158.         Label1.caption = File1.Path
  159.         TheDrive$ = a$ + ":"
  160.         ErrState% = False
  161.  ' if an error occurred go back to the way things were
  162.     If Err Then
  163.         MsgBox (Error$ + Chr$(13) + Chr$(10) + TheDrive$), 16, FormTitle
  164.         TheDrive$ = Left$(OldPath$, 2)
  165.         File1.Path = OldPath$
  166.         If Right$(File1.Path, 1) <> "\" Then
  167.         s$ = File1.Path + "\*.*"
  168.         Else
  169.         s$ = File1.Path + "*.*"
  170.         End If
  171.         y& = SendMessage(TheFocus%, LB_RESETCONTENT, 0, ByVal "")
  172.         x& = SendMessage(TheFocus%, LB_DIR, &HC010, ByVal s$)
  173.         Label1.caption = File1.Path
  174.         Text1.Text = ThePattern
  175.         ErrState% = True    'change the flag so Text1 knows
  176.     End If
  177. End Sub
  178.  
  179. Sub Command1_Click ()
  180.     Select Case LastChange
  181.       Case 1  'process Text1 entry
  182.         Text1_Keypress (13)
  183.  
  184.     Case 2  'we have a file, put together the FullName
  185.         ThePath = File1.Path
  186.         TheFileName = File1.FileName
  187.         FullName = Left$(BuildSpec((File1.Path)), Len(BuildSpec((File1.Path))) - 3) + File1.FileName
  188.         FOpenForm.Hide
  189.  
  190.     Case 3  'let List1 know
  191.         List1_Dblclick
  192.  
  193.     Case 4  'we have a file and a FullName
  194.         FOpenForm.Hide
  195.  
  196.     Case 5  'we have a file, put together the FullName
  197.         ThePath = File1.Path
  198.         FullName = Left$(BuildSpec((File1.Path)), Len(BuildSpec((File1.Path))) - 3) + TheFileName
  199.         FOpenForm.Hide
  200.     Case Else
  201.     End Select
  202. End Sub
  203.  
  204. Sub Command2_Click ()
  205.  ' did the user press cancel?
  206.  ' Change FullName to "CANCEL" so the Parent knows.
  207.     FullName = "CANCEL"
  208.     FOpenForm.Hide
  209. End Sub
  210.  
  211. Sub Command3_Click ()
  212.  
  213. ' The user pressed Load Null, so set FullName to ""
  214.  
  215. FullName = ""
  216. FOpenForm.Hide
  217.  
  218. End Sub
  219.  
  220. Sub File1_Click ()
  221. ' update the textbox and the lastchange flag
  222.   Text1.Text = File1.FileName
  223.   LastChange = 2
  224. End Sub
  225.  
  226. Sub File1_DblClick ()
  227. ' Good, we have a file, let's tell Command1
  228.     LastChange = 2
  229.     Command1_Click
  230. End Sub
  231.  
  232. Sub File1_KeyPress (KeyAscii As Integer)
  233. ' if Return, select File1_DblClick
  234.     If KeyAscii = 13 Then
  235.     If File1.Listindex > -1 Then File1_DblClick
  236.     End If
  237. End Sub
  238.  
  239. Sub Form_GotFocus ()
  240.     If List1Flag% = 0 Then
  241.     List1.SetFocus          ' Set the Focus on List1 to fill the ListBox
  242.     End If
  243. End Sub
  244.  
  245. Sub Form_Load ()
  246.  ' Set the flags for List1 and Text1
  247.     List1Flag% = 0  ' Update Drive/Subdirectory listbox
  248.     Text1Flag% = 0  ' Limit text length
  249.  ' If the Parent didn't specify a FormTitle use the one that's built in.
  250.     If FormTitle = "" Then
  251.     FOpenForm.caption = "File Open"
  252.     FormTitle = FOpenForm.caption
  253.  ' otherwise honor the Parent's specification
  254.     Else
  255.     FOpenForm.caption = FormTitle
  256.     End If
  257.  
  258.  ' If there is a path specification use it, otherwise use the default.
  259.     If ThePath <> "" Then
  260.     If Right$(ThePath, 1) = "\" Then
  261.         ThePath = Left$(ThePath, (Len(ThePath) - 1))
  262.         If Right$(ThePath, 1) = ":" Then ThePath = ThePath + "\"
  263.     End If
  264.     File1.Path = ThePath
  265.     End If
  266.     If ThePath = "" Then ThePath = File1.Path
  267.  
  268.  ' If the Parent specified a new pattern then use it.
  269.     If ThePattern <> "" Then
  270.     File1.Pattern = ThePattern
  271.     End If
  272.  
  273.  ' Finish up loading the form.
  274.     Text1.Text = File1.Pattern
  275.     TheDrive$ = Left$(File1.Path, 2)
  276.     Label1.caption = File1.Path
  277. End Sub
  278.  
  279. Sub List1_Click ()
  280.  ' let Command1 know
  281.     LastChange = 3
  282. End Sub
  283.  
  284. Sub List1_Dblclick ()
  285. ' List1 holds both drives and subdirectories
  286.  If List1.Listi